<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Hash;
use DB;
use App\Http\Requests\AdminLoginPostRequest;
use App\Http\Requests\HomeLoginPostRequest;
use App\Http\Requests;

use App\Http\Controllers\Controller;
use Gregwar\Captcha\CaptchaBuilder;

class SensitiveController extends Controller
{
	/*
		显示添加敏感词过滤页面
	*/
	public function getAdd()
	{
		return view('admin.sensitive.add');
	}

	/*
		执行添加
	*/
	public function postInsert(Request $request)
	{
		//获取部分参数
		$data = $request->only(['keyword','replace']);
		//执行插入
		$res = DB::table('sensitive')->insert($data);
		//判断
		if($res){
			return redirect('/admin/sensitive/index')->with('success','敏感词添加成功');
		}else{
			return back()->with('error','敏感词添加失败');
		}
	}

	/*
		显示过滤词
	*/
	public function getIndex()
	{
		//查询所有的过滤词
		$sensitive = DB::table('sensitive')->paginate(10);

		//解析模板
		return view('admin.sensitive.index',['sensitive'=>$sensitive]);
	}

	/*
		删除过滤词
	*/
	public function postDelete(Request $request)
	{
		$id = $request->input('id');
		//删除传过来的id
		$res = DB::table('sensitive')->where('id',$id)->delete();

		//判断
		if($res){
			echo 2;
		}else{
			echo 1;
		}
	}
}  
